home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / metafontv2.71u.lha / MetaFont / rexx / MakeTeXFont.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1994-11-26  |  12.2 KB  |  458 lines

  1. /*
  2. ** AREXX $VER: MakeTeXFont 1.04
  3. **
  4. ** Send new features and bug reports to 
  5. **
  6. ** Martin Bokaemper
  7. ** Reuthstr. 12
  8. ** 91099 Poxdorf
  9. ** Germany
  10. **
  11. ** Email: mnbokaem@cip.e-technik.uni-erlangen.de (Internet)
  12. **        mab@ame.zer (Zerberus)
  13. **
  14. ** Ulrich Wisser
  15. ** Heerstr. 125
  16. ** 53111 Bonn
  17. **
  18. ** HISTORY:
  19. **
  20. ** 0.80: My 'works-fine-for-me' version modified by Georg Hessmann 13.04.91
  21. **       + Variables for all directories and filenames
  22. **       + ^C and ^D detection 
  23. **       + support for a 'modefile' containing site-specific information
  24. **       + searches for standard magsteps 
  25. **       + support for different format-files
  26. **
  27. ** 0.81: + take new Parameters 'drivertype' and 'pkfilename' 
  28. **       Georg Hessmann 17.04.91
  29. **
  30. ** 0.82: + History 
  31. **       + a lot of small improvements and bugfixes
  32. **       + looking for PK-directory for each device 
  33. **       + checking if the font already exists
  34. **       Martin Bokaemper 21.04.91
  35. **
  36. ** 0.84: + add new parameter 'pkdir' (new since driver version V1.10)
  37. **       Georg Hessmann 09.06.91
  38. **
  39. ** 0.85: + fixed a pkdir/pkfilename mixing bug
  40. **       + slight modifications, now works with old driver versions
  41. **       + changed exit codes
  42. **       + always calls uses plain.base (absolutely no gain in using cmbase)
  43. **       J\"org H\"ohle 24.6.91, 01.08.91
  44. **
  45. ** 0.86: + fixed makedir(pkname) bug
  46. **       J\"org H\"ohle 06.08.91
  47. **
  48. ** 0.90: + add makedir(pkdir)
  49. **       + delete localfont entry in 'modes' file
  50. **       Georg Hessmann 28.08.91
  51. **
  52. ** 1.00: + only one logfile entry per call
  53. **       + ERROR: now reports interpreted sourceline
  54. **       + fonts can be copied to mf:<mode> for font-caching
  55. **       + magstep calculation improved.  now same as in ShowDVI/DVIPrint
  56. **       + MISSING: \scrollmode correctly inserted
  57. **       Ulrich Wisser 25.08.92
  58. **
  59. ** 1.01: + bumped revision number because of partial integration of
  60. **       + versions 0.91 and 1.0 and some personal modifications.
  61. **       Andreas Scherer 31.10.93
  62. **
  63. ** 1.02: + negative magnification factors and dpi values installed.
  64. **       Andreas Scherer 18.01.94
  65. **
  66. ** 1.03: + support for dvips 5.523 resulted in a modified analysis of
  67. **       + the `modes' file.  PKDIR now *always* comes as an argument
  68. **       + of this script (as implemented by Ulrich Wisser).
  69. **       Andreas Scherer 19.01.94
  70. **
  71. ** 1.04: + METAFONT 2.71 returns 0, 5, 10, and 20, so a different ERROR
  72. **       + handling is necessary (and possible).
  73. **
  74. **       Andreas Scherer 2.5.94
  75. */
  76.  
  77. Signal On BREAK_C
  78. Signal On BREAK_D
  79.  
  80. /*
  81. ** Files / Directories
  82. */
  83. LOGDIR       = "MF:log"                 /* directory of the logfiles    */
  84.                                         /* without trailing slash!      */
  85. LOGNAME      = LOGDIR"/MakeTeXFont.log" /* logfile                      */
  86. MODEFILENAME = "MF:config/modes"        /* description of the modes     */
  87. TEXTFM       = "TeX:fonts/tfm/"         /* TeX tfm-files directory      */
  88. VIRMF        = "MF:bin/VirMF"
  89. GFTOPK       = "MF:bin/GFtoPK"
  90. FONTFILENAME = "TeX:config/fontvols"
  91.  
  92. /*
  93. ** Bases. Put in others, if you like.
  94. */
  95. NORMALBASE = "plain"
  96.  
  97. /*
  98. ** Arguments
  99. */
  100. Parse Arg FNTNAME DPI HBASEDPI VBASEDPI DRIVERTYPE PKFILENAME PKDIR .
  101.  
  102. Say "Making font "FNTNAME" at "DPI" dpi and base ("HBASEDPI","VBASEDPI")"
  103.  
  104. If ~Show('Libraries','rexxsupport.library') Then Do
  105.   If ~AddLib('rexxsupport.library',0,-30) Then Do
  106.      Say "No RexxSupport.library ... No Metafont!"
  107.      Exit 5
  108.   End
  109. End
  110.  
  111. DUMMY = Time("Reset")
  112.  
  113. If ~Exists(LOGDIR) Then Do
  114.   Address COMMAND 'MakeDir 'LOGDIR
  115.   If ~Exists(LOGDIR) Then Do
  116.     Call Log("Could not create logdir="LOGDIR)
  117.     Exit 5
  118.   End
  119.   Say "logfile-directory ("LOGDIR"/) did not exist. It was created."
  120. End
  121.  
  122. If ~Exists(LOGNAME) Then Do
  123.   Address COMMAND 'echo >'||LOGNAME
  124.   If ~Exists(LOGNAME) Then Do
  125.     Call Log("Could not create logfile="LOGDIR"/"LOGNAME)
  126.     Exit 5
  127.   End
  128.   Say "logfile did not exist. It was created."
  129. End
  130.  
  131. FNTNAME    = Translate(FNTNAME,XRange('a','z'),XRange('A','Z')) /* lower */
  132. DPI        = Strip(DPI)
  133. HBASEDPI   = Strip(HBASEDPI)
  134. VBASEDPI   = Strip(VBASEDPI)
  135. DRIVERTYPE = Translate(DRIVERTYPE,XRange('a','z'),XRange('A','Z')) /* lower */
  136. PKFILENAME = Translate(PKFILENAME,XRange('a','z'),XRange('A','Z')) /* lower */
  137. PKDIR      = Translate(PKDIR,XRange('a','z'),XRange('A','Z')) /* lower */
  138.  
  139. /*
  140. ** Changed 19.07.92 by Ulrich Wisser
  141. ** Needed to calculate correct DPI sizes
  142. */
  143. Numeric DIGITS 12
  144.  
  145. /*
  146. ** What magstep should the font have?
  147. */
  148. MAG = DPI/HBASEDPI
  149.  
  150. /*
  151. ** MAGMULT.NUM.I set to correct values!
  152. ** 21.07.92 by Ulrich Wisser
  153. ** Needed to calculate correct DPI values.
  154. **
  155. ** Some more values for magstep(-0.5)..magstep(-4) included.
  156. ** 18.01.94 by Andreas Scherer.
  157. */
  158. MAGMULT.0      = 23            /* number of saved MagSteps */
  159.  
  160. MAGMULT.NUM.1  = 1.0           /* MagStep(0)    */
  161. MAGMULT.STR.1  = "0"
  162. MAGMULT.NUM.2  = 1.09544511501 /* MagStep(0.5)  */
  163. MAGMULT.STR.2  = "0.5"
  164. MAGMULT.NUM.3  = 1.2           /* MagStep(1)    */
  165. MAGMULT.STR.3  = "1"
  166. MAGMULT.NUM.4  = 1.31453413801 /* MagStep(1.5)  */
  167. MAGMULT.STR.4  = "1.5"
  168. MAGMULT.NUM.5  = 1.44          /* MagStep(2)    */
  169. MAGMULT.STR.5  = "2"
  170. MAGMULT.NUM.6  = 1.57744096561 /* MagStep(2.5)  */
  171. MAGMULT.STR.6  = "2.5"
  172. MAGMULT.NUM.7  = 1.728         /* MagStep(3)    */
  173. MAGMULT.STR.7  = "3"
  174. MAGMULT.NUM.8  = 2.0736        /* MagStep(4)    */
  175. MAGMULT.STR.8  = "4"
  176. MAGMULT.NUM.9  = 2.48832       /* MagStep(5)    */
  177. MAGMULT.STR.9  = "5"
  178. MAGMULT.NUM.10 = 2.985984      /* MagStep(6)    */
  179. MAGMULT.STR.10 = "6"
  180. MAGMULT.NUM.11 = 3.5831808     /* MagStep(7)    */
  181. MAGMULT.STR.11 = "7"
  182. MAGMULT.NUM.12 = 4.29981696    /* MagStep(8)    */
  183. MAGMULT.STR.12 = "8"
  184. MAGMULT.NUM.13 = 5.159780352   /* MagStep(9)    */
  185. MAGMULT.STR.13 = "9"
  186. MAGMULT.NUM.14 = 0.91287092917 /* magstep(-0.5) */
  187. MAGMULT.STR.14 = "-0.5"
  188. MAGMULT.NUM.15 = 0.83333333333 /* magstep(-1)   */
  189. MAGMULT.STR.15 = "-1"
  190. MAGMULT.NUM.16 = 0.76072577431 /* magstep(-1.5) */
  191. MAGMULT.STR.16 = "-1.5"
  192. MAGMULT.NUM.17 = 0.69444444444 /* magstep(-2)   */
  193. MAGMULT.STR.17 = "-2"
  194. MAGMULT.NUM.18 = 0.63393814526 /* magstep(-2.5) */
  195. MAGMULT.STR.18 = "-2.5"
  196. MAGMULT.NUM.19 = 0.5787037037  /* magstep(-3)   */
  197. MAGMULT.STR.19 = "-3"
  198. MAGMULT.NUM.20 = 0.52828178771 /* magstep(-3.5) */
  199. MAGMULT.STR.20 = "-3.5"
  200. MAGMULT.NUM.21 = 0.48225308641 /* magstep(-4)   */
  201. MAGMULT.STR.21 = "-4"
  202. MAGMULT.NUM.22 = 0.44023482309 /* magstep(-4.5) */
  203. MAGMULT.STR.22 = "-4.5"
  204. MAGMULT.NUM.23 = 0.40187757201 /* magstep(-5)   */
  205. MAGMULT.STR.23 = "-5"
  206.  
  207. MAGMULT.STR.DEFAULT = "???"
  208. MAGSTR              = MAGMULT.STR.DEFAULT
  209.  
  210. /*
  211. ** Changed 21.07.92 by Ulrich Wisser
  212. ** DPI rounding caused troubles sometimes, e.g., for
  213. ** magstep2 with ShowDVI 44x44
  214. */
  215. Do I = 1 To MAGMULT.0
  216.   MAGDPI = (MAGMULT.NUM.I * HBASEDPI) + 0.5
  217.   If Pos('.',MAGDPI) > 0 Then
  218.     MAGDPI = Left(MAGDPI,Pos('.',MAGDPI)-1)
  219.   If MAGDPI = DPI Then Do
  220.     MAG    = MAGMULT.NUM.I
  221.     MAGSTR = MAGMULT.STR.I
  222.     Leave I
  223.   End
  224. End
  225.  
  226. If MAGSTR ~= MAGMULT.STR.DEFAULT Then MAG = 'magstep('magstr')'
  227.  
  228. /*
  229. ** Modes ... search the correct mode in the file MODEFILENAME (see above).
  230. */
  231. If ~Open('MODEFILE',MODEFILENAME,'READ') Then Do
  232.   Call Log("Can't find file "MODEFILENAME"!")
  233.   Exit 5
  234. End
  235.  
  236. Do Until(XRES==HBASEDPI & YRES == VBASEDPI) | EOF('MODEFILE')
  237.   LINE = ReadLn('MODEFILE')
  238.   LINE = Strip(Translate(LINE, ' ', '   '))
  239.   MODE = Word(LINE,1)
  240.   XRES = Word(LINE,2)
  241.   YRES = Word(LINE,3)
  242. End
  243.  
  244. If ~Close('MODEFILE') Then
  245.   Call Log("Can't close mode-file!")
  246.  
  247. If XRES ~= HBASEDPI | YRES ~= VBASEDPI Then Do
  248.   MODE = '' /* for pretty log-entry */
  249.   Call Log("Can't find matching mode!  Make an update in your "MODEFILENAME" file.")
  250.   Exit 5
  251. End
  252.  
  253. /*
  254. ** Produce the complete name of the file.
  255. */
  256. If PKFILENAME="" Then
  257.   PKNAME = PKDIR||DPI'/'FNTNAME'.'DPI'pk'
  258. Else
  259.   PKNAME = PKDIR||PKFILENAME
  260.  
  261. /*
  262. ** Look if the font already is there.
  263. */
  264. If Exists(PKNAME) Then Do
  265.   Say "The font "PKNAME" already exists!"
  266.   Say "Check your driver's configuration!"
  267.   Call Log(PKNAME" already exists; check your driver's configuration!")
  268.   Exit 5
  269. End
  270.  
  271. /*
  272. ** Install the options MetaFont is called with.
  273. */
  274. FORMAT = NORMALBASE
  275.  
  276. If MAGSTR ~= MAGMULT.STR.DEFAULT Then
  277.   OPTIONS = "\mode:="MODE"; mag:=magstep("MAGSTR"); scrollmode; input "FNTNAME
  278. Else
  279.   OPTIONS = "\mode:="MODE"; mag:="MAG"; scrollmode; input "FNTNAME
  280.  
  281. DUMMY = Pragma("directory","MF:")
  282. Address COMMAND
  283.  
  284. /*
  285. ** First: Create the GF-file and the TFM-file and the LOG-file
  286. ** by calling the METAFONT progam.  If anything below fails, you
  287. ** can proceed by hand; all necessary files will be present.
  288. */
  289. Say "Calling MetaFont with format: &"FORMAT" and startup commands: "
  290. Say "'"OPTIONS"'"
  291.  
  292. VIRMF '&'FORMAT' "'OPTIONS'"'
  293.  
  294. /*
  295. ** My version of METAFONT returns codes 0, 5, 10 or 20.
  296. ** Take appropriate actions.
  297. ** Andreas Scherer 2.5.94.
  298. */
  299. ERRORCODE = RC
  300.  
  301. If 5 >= ERRORCODE Then Do
  302.   If 0 < ERRORCODE Then
  303.     Call Error
  304.   Else
  305.     Say FNTNAME" translated without errors."
  306. End; Else Do
  307.   Call Error
  308.   EDITSCRIPT = Word(MyGetEnv("MFREXXEDIT"),1)
  309.   If "" = EDITSCRIPT Then
  310.     EDITSCRIPT = 'MF:rexx/MFEdit.rexx'
  311.   Say "Start editor for "FNTNAME" with "EDITSCRIPT"."
  312.   'rx 'EDITSCRIPT FNTNAME'.mf' 0
  313.   Exit 0
  314. End
  315.  
  316. /*
  317. ** Second: Create the PK-file by calling the GFtoPK program.
  318. ** This is done in the "MF:" directory, not in the final path.
  319. */
  320. GFTOPK FNTNAME'.'DPI'gf'
  321.  
  322. /*
  323. ** Don't delete the GF-file on failure.
  324. */
  325. If Exists(FNTNAME'.'DPI'pk') Then Do
  326.   Delete FNTNAME'.'DPI'gf'
  327.   FileNote FNTNAME'.'DPI'pk' ' "mode='MODE', magstep='MAGSTR'"'
  328. End
  329.  
  330. /*
  331. ** Third: Create all needed directories and try to move the
  332. ** files appropriately.
  333. */
  334.  
  335. /*
  336. ** Don't include last '/' in PKDIR, makedir doesn't like it.
  337. */
  338. PKDIR2 = Left(PKDIR,LastPos("/",PKDIR)-1)
  339.  
  340. If ~Exists(PKDIR2) Then
  341.   If ~MakeDir(PKDIR2) Then Do
  342.     Call Log("MakeDir "PKDIR2" failed")
  343.     Exit 5
  344.   End
  345.  
  346. /*
  347. ** A '/' is required to exist in PKNAME, but don't include it
  348. ** in FULLDIR, makedir doesn't like it.
  349. */
  350. FULLDIR = Left(PKNAME,LastPos("/",PKNAME)-1)
  351.  
  352. If ~Exists(FULLDIR) Then
  353.   If ~MakeDir(FULLDIR) Then Do
  354.     Call Log("MakeDir "FULLDIR" failed")
  355.     Exit 5
  356.   End
  357.  
  358. /*
  359. ** Check the TFM-file; if it doesn't exist, move it there
  360. ** and delete it here.
  361. */
  362. If Exists(TEXTFM) & ~Exists(TEXTFM||FNTNAME'.tfm') Then Do
  363.   Copy FNTNAME'.tfm' TEXTFM clone
  364.   Protect TEXTFM||FNTNAME'.tfm' r
  365. End
  366.  
  367. Delete FNTNAME'.tfm'
  368.  
  369. /*
  370. ** The following section makes a copy of the pk-file to MF:<mode>/PKFILENAME
  371. ** This is useful if you like to copy all new font-files to disks for
  372. ** future font-caching.  See the documentation for further details.
  373. */
  374. /*
  375. If ~Exists(MODE) Then Do
  376.   If ~MakeDir(MODE) Then Do
  377.     Call Log("Makedir "MODE" failed!")
  378.   End
  379. End
  380. If ~Exists(MODE'/'DPI) Then Do
  381.   If ~MakeDir(MODE'/'DPI) Then Do
  382.     Call Log("Makedir "MODE"/"DPI" failed!")
  383.   End
  384. End
  385. If Exists(MODE) Then
  386.   Copy FNTNAME'.'DPI'pk' MODE'/'PKFILENAME
  387. */
  388.  
  389. Copy FNTNAME'.'DPI'pk' PKNAME clone
  390. Delete FNTNAME'.'DPI'pk'
  391. Protect PKNAME r
  392.  
  393. /*
  394. ** Copy/Delete instead Rename to overwrite existing logfile (e.g., from
  395. ** a failed call of MakeTeXfont). Replace by 'move' if you have ARP:
  396. ** i.e., add a line here ``copy = "move" or "mv"''.  This seems to be
  397. ** the case for Ulrich Wisser in Version 1.0, as he uses "move" here.
  398. ** I still assume that most people want to use this script with the
  399. ** original WorkBench, so double moving would cause this to crash.
  400. ** Also, copy/delete unlike move works between devices, too.
  401. */
  402. Copy FNTNAME'.log' LOGDIR'/'FNTNAME'.'DPI'log'
  403. Delete FNTNAME'.log'
  404.  
  405. ELAPSED = Time("ELAPSED")
  406. Call Log("created in "ELAPSED%3600":"Right(ELAPSED%60//60,2,'0')":"Right(ELAPSED%1//60,2,'0'))
  407.  
  408. Exit 0
  409.  
  410. /*
  411. ** Log-function
  412. */
  413. LOG: Procedure Expose LOGNAME FNTNAME MODE HBASEDPI VBASEDPI DPI MAGSTR
  414. Parse Arg MSG
  415.  
  416. MESSAGE = Date()" "Time()": "FNTNAME" for "MODE" ("HBASEDPI","VBASEDPI") with "DPI" dpi (mag="MAGSTR") "'0A'X || MSG
  417. Say MESSAGE
  418.  
  419. If ~Open(LOGFILE,LOGNAME,'Append') Then Do
  420.   Say "Can't open logfile!"
  421.   Return
  422. End
  423.  
  424. DUMMY = Writeln(LOGFILE,MESSAGE)
  425. If ~Close(LOGFILE) Then
  426.   Say "Can't close logfile!"
  427.  
  428. Return
  429.  
  430. ERROR:
  431.   Say "Translation problem, MetaFont returned "ERRORCODE"."
  432.   Call Log("Translation problem, MetaFont returned "ERRORCODE".")
  433. Return
  434.  
  435. BREAK_C:
  436. BREAK_D:
  437.   Call Log "execution aborted!"
  438.   If Exists(FNTNAME'.'DPI'gf') Then
  439.     DUMMY = Delete FNTNAME'.'DPI'gf'
  440.   If Exists(FNTNAME'.log') Then
  441.     DUMMY = Delete FNTNAME'.log'
  442.  
  443.   Exit 1
  444.  
  445. /*
  446. ** When will Arexx supply GetEnv/SetEnv ?
  447. */
  448. MyGetEnv: Procedure
  449. Parse Arg NAME
  450.  
  451. If Open(TEMPFILE,"ENV:"||NAME,'r') Then Do
  452.   GIVES = Readln(TEMPFILE)
  453.   Call Close TEMPFILE
  454. End; Else
  455.   GIVES = ""
  456.  
  457. Return GIVES
  458.